home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.2)
-
- """
- /***************************************************************************
-
- \tAuthor \t\t\t:Charles B. Cosse
- \t
- \tEmail\t\t\t:ccosse@asymptopia.com
- \t\t\t\t\t
- \t\t\t\t\t
- \tCopyright\t\t:(C) 2002,2003 Asymptopia Software.
- \t
- ***************************************************************************/
- /***************************************************************************
- Board.py
-
- \tDescription:
-
- \tA Board is a group of generalized spots.
- \tThis class should be used as a base class for various types of
- \tboards -- blackjack tables,cw puzzles,checkers -- any thing with
- \tfixed spots. The game pieces are attirbutes of the board.
- \tIf you want a background image, blit that as background from the
- \toutermost game class, not this class, as this is a Group.
- \t
- \tGroup base class provides: Add,copy,empty,has,sprites,remove,update
- \tShould not give both empty_spot_image and background_image; either/or.
-
- \tIf background image, then we break-up the background image into default
- \tspot images. If neither, of course, then it's an *invisible* spot.
- \t*Derived* classes set the location of the self.spots.
- \tThe way the images are passed to __init__, the look of the board(ie spot
- \timages) is still controlled from outside. No need to manaully
- \tdo anything unless get the spots through the get_spots() method.
- \tXC,YC are center of board -- boards all assumed array like
- \t
- \tLatest: submission is M*N array of invisible spots; validate_submission(self.submission);
-
- ***************************************************************************/
-
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. (Please note that if you use this *
- * code you must give credit by including the Author and Copyright *
- * info at the top of this file). *
- ***************************************************************************/
-
- """
- import pygame
- from pygame.locals import *
- from Spot import Spot
-
- class Board(pygame.sprite.Group):
-
- def __init__(self, M, N, XC, YC, background_image, default_spot_image):
- pygame.sprite.Group.__init__(self)
- self.M = M
- self.N = N
- self.XC = XC
- self.YC = YC
- self.default_spot_image = default_spot_image
- self.map = None
- self.num_commited = 0
- if background_image and not default_spot_image:
- self.make_background_spots(background_image)
- elif default_spot_image and not background_image:
- self.make_default_spots(default_spot_image)
- else:
- self.make_invisible_spots(None)
-
-
- def get_map(self):
- m = []
- for midx in range(self.M):
- m.append([])
- for nidx in range(self.N):
- for spot in self.sprites():
- if spot.getMN()[0] == midx and spot.getMN()[1] == nidx:
- if spot.guest:
- m[midx].append(spot.guest.str_val)
- else:
- m[midx].append('')
-
-
-
-
- return m
-
-
- def check4guest(self, m, n):
- if m < 0 and m > self.M - 1 and n < 0 or n > self.N - 1:
- return 0
-
- spot = self.get_spotMN(m, n)
- if spot.guest == None:
- return 0
- else:
- return 1
-
-
- def get_listofheads(self):
- heads = []
- for spot in self.sprites():
- if spot.guest:
- if spot.AMHEAD:
- heads.append(spot)
-
-
-
- return heads
-
-
- def clear_spots(self):
- for spot in self.sprites():
- spot.remove(self)
-
-
-
- def get_spotMN(self, m, n):
- for spot in self.sprites():
- MN = spot.getMN()
- if MN[0] == m and MN[1] == n:
- return spot
-
-
-
-
- def take_guestMN(self, tile, m, n):
- for spot in self.sprites():
- MN = spot.getMN()
- if MN[0] == m and MN[1] == n:
- spot.take_guest(tile, 1)
- return spot
-
-
-
-
- def get_num_commited(self):
- return self.num_commited
-
-
- def increment_num_commited(self):
- self.num_commited = self.num_commited + 1
-
-
- def get_guest_by_str(self, str_val):
- for spot in self.sprites():
- if spot.guest and spot.guest.str_val == str_val:
- return spot.pop_guest()
-
-
- return None
-
-
- def get_spots(self):
- return self.sprites()
-
-
- def make_background_spots(self, background_image):
- for midx in range(self.M):
- for nidx in range(self.N):
- self.add(Spot(default_spot_image, midx, nidx))
-
-
-
-
- def make_default_spots(self, default_spot_image):
- XC = self.XC
- YC = self.YC
- M = self.M
- N = self.N
- for midx in range(0, M):
- for nidx in range(0, N):
- if self.M == 1:
- spot = Spot(default_spot_image, midx, nidx, 'REG')
- elif abs(M / 2 - midx) == abs(N / 2 - nidx):
- img = default_spot_image[:-4] + '_2XL.gif'
- spot = Spot(img, midx, nidx, '2XL')
- elif midx == -nidx + (N / 2 - 4):
- img = default_spot_image[:-4] + '_3XL.gif'
- spot = Spot(img, midx, nidx, '3XL')
- elif midx == -nidx + N / 2 + 16:
- img = default_spot_image[:-4] + '_3XL.gif'
- spot = Spot(img, midx, nidx, '3XL')
- elif midx == +nidx - (N / 2 + 4):
- img = default_spot_image[:-4] + '_3XL.gif'
- spot = Spot(img, midx, nidx, '3XL')
- elif midx == +nidx + 8:
- img = default_spot_image[:-4] + '_3XL.gif'
- spot = Spot(img, midx, nidx, '3XL')
- elif not midx == 0 and nidx == 0:
- if not nidx == N - 1 and midx == M - 1:
- if nidx == 0 and midx == M - 1 and nidx == N - 1 and midx == 0:
- img = default_spot_image[:-4] + '_2XW.gif'
- spot = Spot(img, midx, nidx, '2XW')
- elif not midx == M / 2 and nidx == N / 4:
- if not nidx == N / 2 and midx == M / 4:
- if nidx == N / 2 and midx == 3 * M / 4 and nidx == 3 * N / 4 and midx == M / 2:
- img = default_spot_image[:-4] + '_2XW.gif'
- spot = Spot(img, midx, nidx, '2XW')
- elif nidx == N / 2 and midx == 0:
- img = default_spot_image[:-4] + '_3XW.gif'
- spot = Spot(img, midx, nidx, '3XW')
- elif nidx == N / 2 and midx == M - 1:
- img = default_spot_image[:-4] + '_3XW.gif'
- spot = Spot(img, midx, nidx, '3XW')
- elif nidx == 0 and midx == M / 2:
- img = default_spot_image[:-4] + '_3XW.gif'
- spot = Spot(img, midx, nidx, '3XW')
- elif nidx == N - 1 and midx == M / 2:
- img = default_spot_image[:-4] + '_3XW.gif'
- spot = Spot(img, midx, nidx, '3XW')
- else:
- spot = Spot(default_spot_image, midx, nidx, 'REG')
- w = spot.image.get_width()
- h = spot.image.get_height()
- spot.rect.center = (XC + (-N / 2 + nidx + 0.5) * w, YC + (-M / 2 + midx + 0.5) * h)
- self.add(spot)
-
-
-
-
- def make_invisible_spots(self, invisible):
- print 'make_invisible_spots'
- for midx in range(self.M):
- for nidx in range(self.N):
- self.add(Spot(invisible, midx, nidx))
-
-
-
-
-